package com.my.study.mq.consumer.demo;

import com.my.study.entity.User;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 普通队列消费者
 *
 * @author: yidujun
 * @create: 2021/03/16 10:58
 */
@Component
@RabbitListener(queues = "demoQueue")
public class DefaultConsumer {

    /**
     *  消费消息
     *
     * @param msg 待消费消息
     * @RabbitHandler  代表此方法为接受到消息后的处理方法
     */
    @RabbitHandler
    public void received(String msg) {
        System.out.println("[demoQueue] recieved message: " + msg);
    }

    @RabbitHandler
    public void receivedList(List<String> msg) {
        System.out.println("[demoQueue] recieved message: " + msg.toString());
    }

    @RabbitHandler
    public void receivedUser(User msg) {
        System.out.println("[demoQueue] recieved message: " + msg.toString());
    }

    @RabbitHandler(isDefault = true)
    public void receivedListUser(List<User> msg) {
        System.out.println("[demoQueue] recieved message: " + msg.toString());
    }
}
